// const btn = document.getElementById("btn")
const msg = document.getElementById("msg")
// const msgList = document.getElementById("list")


// let ws
// const user = {
//     name: "robin",
//     password: "1234"
// }

msg.addEventListener("click", () => {

    // const headers = new Headers()
    // headers.set("authorization",user.token)

    // fetch("http://localhost:3000/list", {
    //     headers,

    // })
    console.log("!!!!!!!!!!!Click Start!!!!!!!!!!!!!!");
    const data = {
        'Authorization': 'Bearer token',
        'Custom-Header': 'value',
        'Access_Token': 'cdee710e127ec8ce93f1eda28147da73'
   };
    // const url = "http://10.0.0.232:8101/topic/support/get_checkpoint_details_used_by_cucumber"
    // const url = "http://www.testbibo.com/api/topic/1.0/json/support/get_checkpoint_details_used_by_cucumber"
    // const url = "http://www.testbibo.com/api/topic/1.0/json/block/import_file_data_via_sse?media_item_id=26050&class_checkpoint_id=599770"
    const url = "http://www.testbibo.com/api/topic/1.0/json/block/import_file_data_via_sse?media_item_id=26050&class_checkpoint_id=599770"
    console.log(333);
    const es = new EventSourcePolyfill(url,{headers: {
                                       'Access_Token': 'cdee710e127ec8ce93f1eda28147da73',
                                       'Access-Token': 'cdee710e127ec8ce93f1eda28147da73',
                                       'Accept':'*/*',
                                       'Accept-Encoding':'gzip, deflate, br'
                                     }
                                   })
    let str = ''
    es.addEventListener('message', e => {
        console.log("MESSAGE:"+e.data);
    })
    es.addEventListener('progress', e => {
        console.log("Progress:"+e.data);
    })
    es.addEventListener('result', e => {
       console.log("Result:"+e.data);
    })
    es.addEventListener('close', e => {
        console.log("CLOSE:"+e.data);
        es.close();
    })
    console.log("!!!!!!!!!!!Click End!!!!!!!!!!!!!!");
})






// function wsInit() {
//     ws = new WebSocket("ws://localhost:5000")
//     ws.addEventListener("open", e => {
//         console.dir("client connected");
//     })
//     ws.onopen = function () {
//         console.log("已连接TCP服务器");
//     };
//     ws.onmessage = function (msg) {
//         console.dir("get message");
//         console.log(msg.data);
//         const data = JSON.parse(msg.data)
//         if (data.type != 1) {
//             const li = document.createElement("li")
//             li.innerText = data.msg
//             msgList.appendChild(li)
//         } else {
//             start = 0
//         }

//     };

// }





// wsInit()

// ws.onclose = function () {
//     console.log('服务器已经断开');
//     setTimeout(() => {
//         wsInit()
//     }, 2000);
// };